
<template>
  <div class="execution">
   <el-container>
	   <el-main>
		   <avue-crud ref="crud"
		   	                :page.sync="page"
		   	                :data="tableData"
		   	                :table-loading="tableLoading"
		   	                :option="tableOption"
		   	                @on-load="getList"
		   	                @search-change="searchChange"
		   	                @refresh-change="refreshChange"
		   	                @size-change="sizeChange"
		   	                @current-change="currentChange"
		   	                @row-update="handleUpdate"
		   	                @row-save="handleSave"
		   	                @row-del="rowDel">
		   	   
		   	                <template slot="level"
		   	                          slot-scope="scope">
		   	                  <el-tag v-if="scope.label == '非常紧急'" style="background-color: #FF0000;color: #FFFFFF;">{{scope.label}}</el-tag>
		   	                  <el-tag v-if="scope.label == '紧急'" style="background-color: #FF6666;color: #FFFFFF;">{{scope.label}}</el-tag>
		   	                  <el-tag v-if="scope.label == '正常'" style="background-color: #FFBBBB;color: #FFFFFF;">{{scope.label}}</el-tag>
		   	                </template>
		   	   
		   	                <template slot="isFinish"
		   	                          slot-scope="scope">
		   	                   <el-tag v-if="scope.label == '已完成'" style="color:#50C050 ;">{{scope.label}}</el-tag>
		   	                   <el-tag v-if="scope.label == '未完成'">{{scope.label}}</el-tag>
		   	                </template>
		   	   
		   	                <template
		   	                  slot="menu"
		   	                  slot-scope="scope">
		   	                  <el-button
		   	                    type="text"
		   	                    icon="el-icon-edit"
		   	                    @click="setTask(scope.row,scope.index)">查看/分配任务
		   	                  </el-button>
		   	               </template>
		   	   
		   	     </avue-crud>
		    
		     
		   
		   <el-dialog
			  :visible.sync="dialogFormVisible"
			  title="分配协作人"
			  width="90%"
			  @close="dictItemVisible">
			  <avue-crud
				ref="crudItem"
				:page.sync="itemPage"
				:data="tableDictItemData"
				
				:before-open="handleBeforeOpen"
				:option="tableDictItemOption"
				@size-change="itemSizeChange"
				@current-change="itemCurrentChange"
				@row-update="handleItemUpdate"
				@row-save="handleItemSave"
				@row-del="rowItemDel">
				<template slot="level"
						  slot-scope="scope">
				  <el-tag v-if="scope.label == '非常紧急'" style="background-color: #FF0000;color: #FFFFFF;">{{scope.label}}</el-tag>
				  <el-tag v-if="scope.label == '紧急'" style="background-color: #FF6666;color: #FFFFFF;">{{scope.label}}</el-tag>
				  <el-tag v-if="scope.label == '正常'" style="background-color: #FFBBBB;color: #FFFFFF;">{{scope.label}}</el-tag>
				</template>
				<template slot="isFinish"
						  slot-scope="scope">
				  <el-tag v-if="scope.label == '已完成'" style="color:#50C050 ;">{{scope.label}}</el-tag>
				  <el-tag v-if="scope.label == '未完成'">{{scope.label}}</el-tag>
				</template>
			  </avue-crud>
			</el-dialog>
						
	   </el-main>
	</el-container>
  </div>
</template>

<script>
  
  import {tableOption,tableOption2} from '../../../const/task.js'

  export default {
    name: 'Task',
    data() {
      return {
        searchForm: {},
        tableData: [],
        page: {
            total: 0, // 总页数
            currentPage: 1, // 当前页数
            pageSize: 20 // 每页显示多少条
        },
        tableLoading: false,
        tableOption: tableOption,
        ///分配成员相关
        dialogFormVisible: false,
        itemPage: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20 // 每页显示多少条
        },
		taskId:undefined,
        // form: {
        //   taskId: undefined
        // },
        tableDictItemData: [],
        tableDictItemOption: tableOption2,

      }
    },
    created() {
    },
    mounted: function () {
    },
    computed: {
		
    },
    methods: {
      //
      getList(page, params) {
          this.tableLoading = true
		  var loginId = this.$store.getters.getUser.user.id
		  this.axios({
		  	method: "get",
		  	url: 'http://localhost:8080/message/task/page?loginId='+loginId,
		  	params: Object.assign(
		  			{
		  				current:this.page.currentPage,
		  				size: this.page.pageSize,
		  			},
		  			this.searchForm
		  		)
		  		
		  }).then(response => {
              this.tableData = response.data.data.records
              this.page.total = response.data.data.total
              this.tableLoading = false
          }).catch(() => {
              this.tableLoading=false
          })
		  
      },
      rowDel: function (row, index) {
          this.$confirm('是否确认删除?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
          }).then(function () {
			  var url = 'http://localhost:8080/message/task/'+row.id
			  return axios.delete(url)
              // return delObj(row.id)
          }).then(data => {
              this.$message.success('删除成功')
              this.getList(this.page)
          })
      },
      handleUpdate: function (row, index, done,loading) {
		  
          var url = 'http://localhost:8080/message/task'
          let data = row
          this.axios.put(url,data).then(data => {
              this.$message.success('修改成功')
              done()
              this.getList(this.page)
          }).catch(() => {
              loading();
          });
      },
      handleSave: function (row, done,loading) {
		    // console.log(this.$store.getters.getUser.user.id)
		  var loginId = this.$store.getters.getUser.user.id
		  var loginName = this.$store.getters.getUser.user.name
		  var url = 'http://localhost:8080/message/task?loginId='+loginId+'&username='+loginName
		  this.axios.post(url,row).then(data => {
              this.$message.success('添加成功')
              done()
              this.getList(this.page)
          }).catch(() => {
              loading();
          });
      },
      sizeChange(pageSize){
          this.page.pageSize = pageSize
      },
      currentChange(current){
          this.page.currentPage = current
      },
      searchChange(form, done) {
          this.searchForm = form
          this.page.currentPage = 1
          this.getList(this.page, form)
          done()
      },
      refreshChange() {
          this.getList(this.page)
      },
      rowStyle({row,column,rowIndex}){
          if(rowIndex%2===0){
             return {
                 backgroundColor:'#eee',
                 color:'#fff'
             }
           }
      },
      //分配相关//////////////////////////////////////////////////////////////////
      dictItemVisible: function () {
        this.dialogFormVisible = false
        this.itemPage.currentPage = 1
      },
      setTask: function (row) {
        this.taskId = row.id
        this.getDictItemList()
      },
      getDictItemList() {
        this.dialogFormVisible = true
		
		this.axios({
			method: "get",
			url: 'http://localhost:8080/message/task/getTaskUserById/'+this.taskId,
			params: Object.assign(
					{
						current:this.page.currentPage,
						size: this.page.pageSize,
					},
					this.searchForm
				)
				
		}).then(response => {
          this.tableDictItemData = response.data.data.records
          this.itemPage.total = response.data.data.total
        })
		
      },
      handleBeforeOpen(done) {
        // this.form.taskId = this.taskId
        done()
      },
      handleItemSave: function (row, done) {
        console.log(this.taskId)
		var url ='http://localhost:8080/message/task/addTaskUser/'+this.taskId
		this.axios.post(url,row).then(() => {
          this.$message.success('添加成功')
          this.getDictItemList()
          done()
        })
      },
      handleItemUpdate: function (row, index, done) {
		  var url ='http://localhost:8080/message/task/updateTaskUser/'+this.taskId
		  this.axios.put(url,row).then(() => {
          this.$message.success('修改成功')
          this.getDictItemList()
          done()
        })
      },
      rowItemDel: function (row) {
        this.$confirm('是否确认删除数据?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function () {
			console.log(123)
			var url ='http://localhost:8080/message/task/deleteTaskUser/'+row.id
			return axios.delete(url)
        }).then(() => {
          this.getDictItemList()
          this.$message.success('删除成功')
        }).catch(function () {
        })
      },
      itemSizeChange(pageSize) {
        this.itemPage.pageSize = pageSize
        this.getDictItemList()
      },
      itemCurrentChange(current) {
        this.itemPage.currentPage = current
        this.getDictItemList()
      }

    }
  }
</script>

<style lang="scss" scoped>
</style>
